package cn.org.eshow.webapp.action.h5;

import cn.org.eshow.bean.query.BillQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.model.Bill;
import cn.org.eshow.service.BillManager;
import cn.org.eshow.util.PageUtil;
import cn.org.eshow.webapp.action.BaseAction;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 账单H5接口
 */
@Results({@Result(name = "input", location = "add"),
        @Result(name = "list", type = "redirect", location = ""),
        @Result(name = "success", type = "redirect", location = "view/${id}"),
        @Result(name = "redirect", type = "redirect", location = "${redirect}")})
@AllowedMethods({"search", "view"})
public class BillAction extends BaseAction {

    @Autowired
    private BillManager billManager;

    private List<Bill> bills;
    private BillQuery query = new BillQuery();
    private Bill bill = new Bill();

    public String search() {
        Page<Bill> page = billManager.search(query);
        bills = page.getDataList();
        saveRequest("page", PageUtil.conversion(page));
        saveRequest("query", query);
        return NONE;
    }

    public String view() {
        bill = billManager.get(id);
        return NONE;
    }

    public List<Bill> getBills() {
        return bills;
    }

    public void setBills(List<Bill> bills) {
        this.bills = bills;
    }

    public BillQuery getQuery() {
        return query;
    }

    public void setQuery(BillQuery query) {
        this.query = query;
    }

    public Bill getBill() {
        return bill;
    }

    public void setBill(Bill bill) {
        this.bill = bill;
    }
}
